﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using EBSystem.Data;
using EBSystem.SQL;
using static System.Net.Mime.MediaTypeNames;

namespace EBSystem.Pages.UserPages
{
    /// <summary>
    /// AddDeliveryAddressWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AddDeliveryAddressWindow : Window
    {
        public AddDeliveryAddressWindow()
        {
            InitializeComponent();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            UserSourcePage userSourcePage = MainWindow.GetThisMainWindow().mainContentControl.Content as UserSourcePage;
            if (provinceTextBox.Text is null || provinceTextBox.Text == "" ||
                cityTextBox.Text is null || cityTextBox.Text == "" ||
                countyTextBox.Text is null || countyTextBox.Text == "" ||
                detailedAddressTextBox.Text is null || detailedAddressTextBox.Text == "")
            {
                MessageBox.Show("请输入完整地址");
                return;
            }

            SQLConnection.AddDeliveryAddress(provinceTextBox.Text, cityTextBox.Text, countyTextBox.Text, detailedAddressTextBox.Text);
            string item = provinceTextBox.Text + "  " + cityTextBox.Text + "  " + countyTextBox.Text + "  " + detailedAddressTextBox.Text;
            TextBox textBox = new();
            textBox.Text = item;
            textBox.Margin = new(0, 10, 10, 10);
            textBox.IsReadOnly = true;
            textBox.TextWrapping = TextWrapping.WrapWithOverflow;
            userSourcePage?.deliveryAddress.Children.Add(textBox);
            MessageBox.Show("添加成功");
            Close();
        }
    }
}
